﻿using Kw.Combinatorics;
using System;

namespace Kw.CombinatoricsExamples
{
    class PermutationExample03
    {
        static void Main ()
        {
            int width = 6;
            long rank = 9;

            // Create a permution with 6 elements:

            Permutation pn = new Permutation (width, rank);

            // Assign -1 to Rank to get the last rank:

            pn.Rank = -1;

            // A row can be treating as a string:

            string text = pn.ToString () + "  width=" + pn.Width + ", rank=" + pn.Rank;
            Console.WriteLine (text);

            // Increment/decrement operators will wrap-around if they go past limits:

            ++pn;
            Console.WriteLine ("\n{0}  width={1}, rank={2}", pn, pn.Width, pn.Rank);

            // Create a permutation from a known sequence:

            pn = new Permutation (new int[] { 5, 0, 3, 1, 2, 4 });

            Console.WriteLine ("\n{0}  width={1}, Rank={2}", pn, pn.Width, pn.Rank);
        }

        /* Output:

        { 5, 4, 3, 2, 1, 0 }  width=6, rank=719

        { 0, 1, 2, 3, 4, 5 }  width=6, rank=0

        { 5, 0, 3, 1, 2, 4 }  width=6, Rank=612

        */
    }
}
